<?php
use yii\helpers\Html;
$post=\Yii::$app->session->getFlash('post');
?>
<?php $this->beginBlock('title'); ?>
    <?php if(isset($model['id'])):?>编辑<?php else:?>新增<?php endif;?>游戏版本
<?php $this->endBlock();?>
<?php $this->beginBlock('breadcrumb'); ?>
<li><a href="<?php echo \Yii::$app->urlManager->createUrl('/game-version/index')?>">游戏版本</a></li>
<li class="active"><a href="<?php echo \Yii::$app->urlManager->createUrl('/game-version/edit',['id'=>isset($model['id'])?$model['id']:0]);?>"><?php if(isset($model['id'])):?>编辑<?php else:?>新增<?php endif;?>游戏版本</a></li>
<?php $this->endBlock();?>

<style>
.auto_height { height: 350px; OVERFLOW-Y: auto; SCROLLBAR-FACE-COLOR: #ffffff; }
</style>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::$app->request->baseUrl; ?>/js/bootstrap-datetimepicker/css/datetimepicker.css"/>
<div class="row">
	<div class="col-sm-12">
		<section class="panel">
			<div class="panel-body">
				<div class="form">
					<form class="cmxform form-horizontal tasi-form" method="post" action="<?php echo \Yii::$app->urlManager->createUrl('/game-version/save');?>">
						<?php if($model):?>
						<div class="form-group">
							<label for="game_name" class="control-label col-lg-2">所属游戏</label>
							<div class="col-lg-10">
                               	<input class="form-control" id="game_name" name="game_name" value="<?=Html::encode($model['game']['game_name']?:'尚未指派');?>" type="text" disabled="" />
                            </div>
						</div>
						<?php else:?>
						<div class="form-group">
							<label for="game_name" class="control-label col-lg-2">所属游戏</label>
							<div class="col-lg-10">
                               	<span id="game_name"></span><a href="#addGameModal" data-toggle="modal" class="btn btn-success">查找并添加游戏</a>
                            </div>
						</div>
						<?php endif;?>
						<div class="form-group">
                            <label for="version_title" class="control-label col-lg-2">版本标题</label>
                            <div class="col-lg-10">
                                <input class="form-control " id="version_title" type="text" value="<?php if(isset($post['version_title'])){ echo $post['version_title'];}else{ echo Html::encode($model['version_title']?:''); }?>" name="version_title" required />
                            </div>
                        </div>
						<div class="form-group">
                            <label for="version" class="control-label col-lg-2">版本号</label>
                            <div class="col-lg-10">
                                <input class="form-control " id="version" type="text" value="<?php if(isset($post['version'])){ echo $post['version'];}else{ echo Html::encode($model['version']?:''); }?>" name="version" required />
                            </div>
                        </div>
						<div class="form-group">
                            <label for="version_size" class="control-label col-lg-2">版本大小</label>
                            <div class="col-lg-10">
                                <input class="form-control " id="version_size" type="text" value="<?php if(isset($post['version_size'])){ echo $post['version_size'];}else{ echo Html::encode($model['version_size']?:''); }?>" name="version_size" required />
                            </div>
                        </div>
						<div class="form-group">
                            <label for="version_os" class="control-label col-lg-2">系统信息</label>
                            <div class="col-lg-10">
                                <input class="form-control " id="version_os" type="text" value="<?php if(isset($post['version_os'])){ echo $post['version_os'];}else{ echo Html::encode($model['version_os']?:''); }?>" name="version_os" />
                            </div>
                        </div>
						<div class="form-group">
                            <label for="soft_url" class="control-label col-lg-2">下载地址</label>
                            <div class="col-lg-10">
                                <input class="form-control " id="soft_url" type="text" value="<?php if(isset($post['soft_url'])){ echo $post['soft_url'];}else{ echo Html::encode($model['soft_url']?:''); }?>" name="soft_url" required />
                            </div>
                        </div>
						<div class="form-group">
                            <label for="c_package_name" class="control-label col-lg-2">包名</label>
                            <div class="col-lg-10">
                                <input class="form-control " id="c_package_name" type="text" value="<?php if(isset($post['c_package_name'])){ echo $post['c_package_name'];}else{ echo Html::encode($model['c_package_name']?:''); }?>" name="c_package_name" required />
                            </div>
                        </div>
						<div class="form-group">
                            <label for="channelId" class="control-label col-lg-2">频道</label>
                            <div class="col-lg-10">
                                <input class="form-control " id="channelId" type="text" value="<?php if(isset($post['channelId'])){ echo $post['channelId'];}else{ echo Html::encode($model['channelId']?:''); }?>" name="channelId" required />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-offset-2 col-lg-10">
                                <input type="hidden" name="_csrf" id="_csrf" value="<?=\Yii::$app->request->csrfToken; ?>" />
        						<?php if(isset($model['id'])):?><input type="hidden" name="id" value="<?=$model['id'];?>" /><?php endif;?>
                                <input type="hidden" name="game_id" id="game_id" value="<?=$model['game_id'];?>" />
                                <button class="btn btn-success" type="submit"> 保存</button>
                                <button class="btn btn-default" type="button" onclick="javascript:history.go(-1)"> 取消</button>
                            </div>
                        </div>
                    </form>
                </div>
			</div>
		</section>
	</div>
</div>
<!-- Modal -->
<div class="modal fade" id="addGameModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">添加所属游戏</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12">
						<section class="panel">
							<div class="panel-body">
								<form class="form-inline" role="form" id="game_search_form">
									<div class="form-group">
										<label class="sr-only" for="key">关键字</label>
				                        <input type="text" class="form-control" id="modal_key" name="modal_key" value="" placeholder="游戏名称">
				                    </div>
				                    <div class="form-group">
				                    	<select class="form-control" name="state_id">
											<option value="" <?php if(\Yii::$app->request->get('state_id')!=''):?>selected<?php endif;?>>--所有状态--</option>
                                            <?php foreach($states as $item):?>
                								<option value="<?=$item['state_id'];?>" <?php if($item['state_id']==\Yii::$app->request->get('state_id')):?>selected<?php endif;?>><?=$item['state_name'];?></option>
                							<?php endforeach;?>
										</select>
				                    </div>
									<button type="button" class="btn btn-info" id="GameFind"><i class="fa fa-search"></i> 查询</button>
								</form>
							</div>
							<div id="GameList">

							</div>
						</section>
					</div>
                </div>
            </div>
            <div class="modal-footer" style="display:none;">
                <button data-dismiss="modal" class="btn btn-default" type="button" id="closeModel">Close</button>
            </div>
        </div>
    </div>
</div>
<!-- modal -->
<?php
$this->beginBlock('script');
?>
<script type="text/javascript" src="<?php echo Yii::$app->request->baseUrl; ?>/js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="<?php echo Yii::$app->request->baseUrl; ?>/js/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript">
//时间选择
$('.form_datetime').datetimepicker({
    format: 'yyyy-mm-dd hh:ii',
    autoclose:true,
    language: "zh-CN",
})

//游戏模态框的搜索
$("#GameFind").click(function() {
    $.get("<?php echo \Yii::$app->urlManager->createUrl('/game/search-by-version');?>", $("#game_search_form").serialize(), function(data) {
        $("#GameList").html(data);
    },'html');
    $("#GameList").addClass("auto_height");
});

function assignGame(game_id,game_name){
	if(game_id>0 && game_name!=''){
		$("#game_name").text(game_name);
		$("#game_id").val(game_id);
		//关闭模态框
		$("#closeModel").trigger("click");
	}else{
	    alert("指派失败，参数错误");
	    return false;
	}
}
</script>
<?php $this->endBlock('script');?>